﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TlvLib.SiChuan
{
    public class CarInfo
    {
        private static System.IO.TextWriter writer;
        private static System.IO.TextReader reader;
        private static FileStream fs;
        private static UInt32 _sn;

        static CarInfo()
        {
            fs = File.Open("sn.log", FileMode.OpenOrCreate);
            writer = new StreamWriter(fs);
            reader = new StreamReader(fs);

            uint.TryParse(reader.ReadLine() ?? "0", out _sn);
        }

        //必填项目
        public UInt32 SN;   //流水号
        public string KKBH; //卡口编号
        public string CDBH; //车道编号
        public string FXBH; //方向编号
        public string SBBH; //设备编号
        public string CTHPHM; //车头号牌号码
        public string HPYZ; //车头尾号牌一致性
        public DateTime JGSJ; //过车时间
        public string[] TXLJs; //图像路径
        public UInt16 CTHPYS;
        public double CLSD;





        public CarInfo()
        {
            SN = GetNextSN();

        }

        private static uint GetNextSN()
        {
            var sn = ++_sn;
            if (sn == uint.MaxValue)
            {
                sn = 0;
            }

            PersistSn(sn);
            return sn;
        }

        private static void PersistSn(uint sn)
        {
            fs.Seek(0, SeekOrigin.Begin);
            writer.WriteLine(sn);
            writer.Flush();
        }
    }
}
